<template>
  <div class="div">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
        <el-form-item label="密码">
        <el-input v-model="form.pass"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
    data() {
        return {
            form:{
                name:"",
                pass:""
            }
        }
    },
    methods: {
        onSubmit(){
            this.$axios.post("https://www.liulongbin.top:8888/api/private/v1/login",{
                username:this.form.name,
                password:this.form.pass
            }).then((res)=>{
                console.log(res);
                if(res.data.meta.status=="200"){
                    localStorage.setItem("token",res.data.data.token)
                    this.$router.push({path:"/shop"})
                    alert('登录成功')
                }
            }).catch((res)=>{
                alert('登录失败')
            })
        }
    },
}
</script>
<style lang="scss">
    .div{
        width: 400px;
        height: 300px;
        margin: 100px auto;
    }
</style>